package lk.service.blogspringboot.service.impl;

import lk.service.blogspringboot.domain.FollowingDetail;
import lk.service.blogspringboot.mapper.FollowingDetailMapper;
import lk.service.blogspringboot.service.FollowingDetailService;
import lk.service.blogspringboot.util.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 关注详细信息表(FollowingDetail)表服务实现类
 *
 * @author LK
 * @since 2024-08-25 20:47:41
 */
@Service("followingDetailService")
public class FollowingDetailServiceImpl implements FollowingDetailService {
    @Resource
    private FollowingDetailMapper followingDetailMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public R queryById(Integer id) {
        return R.ok().setData(this.followingDetailMapper.queryById(id));
    }

    /**
     * 全查询
     *
     * @param followingDetail 筛选条件
     * @return 查询结果
     */
    @Override
    public R queryAll(FollowingDetail followingDetail) {
        return R.ok().setData(this.followingDetailMapper.queryAll(followingDetail));
    }

    /**
     * 新增数据
     *
     * @param followingDetail 实例对象
     * @return 实例对象
     */
    @Override
    public R insert(FollowingDetail followingDetail) {
        this.followingDetailMapper.insert(followingDetail);
        return R.ok().setData(followingDetail);
    }

    /**
     * 修改数据
     *
     * @param followingDetail 实例对象
     * @return 实例对象
     */
    @Override
    public R update(FollowingDetail followingDetail) {
        this.followingDetailMapper.update(followingDetail);
        return R.ok().setData(this.queryById(followingDetail.getId()));
    }

    @Override
    public R deleteFollowingByUserNameAndFolloweeName(String userName, String followingUserName) {
        if (this.followingDetailMapper.deleteFollowingByUserNameAndFolloweeName(userName, followingUserName)) {
            return R.ok();
        }else {
            return R.fail();
        }
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public R deleteById(Integer id) {
        boolean del = this.followingDetailMapper.deleteById(id) > 0;
        return R.ok().setData(del);
    }

    @Override
    public R queryIsFollowing(String userName, String followingUserName) {
        if (this.followingDetailMapper.queryIsFollowing(userName, followingUserName)) {
            return R.ok().setData(true);
        }else {
            return R.ok().setData(false);
        }
    }
}

